﻿using LeakView.common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeakView.service
{
    class AlarmModal : Splashable
    {
        public static readonly AlarmModal me = new AlarmModal();

        // 泄漏报警
        private AlarmTag alarmForXL = new AlarmTag();
        public AlarmTag AlarmForXL { get => alarmForXL; }
        // 离线报警
        private AlarmTag alarmForLX = new AlarmTag();
        public AlarmTag AlarmForLX { get => alarmForLX; }
        // 输差报警
        private AlarmTag alarmForSC = new AlarmTag();
        public AlarmTag AlarmForSC { get => alarmForSC; }
        // 压差报警
        private AlarmTag alarmForYC = new AlarmTag();
        public AlarmTag AlarmForYC { get => alarmForYC; }

        private AlarmModal()
        {

        }

        void Splashable.splash(bool flag)
        {
            AlarmForXL.IsAlarm = MainModule.current.Leaking;

            AlarmForLX.IsAlarm = !(MainModule.pair.Value.Valid && MainModule.status.Value.Value.head && MainModule.status.Value.Value.tail);

        }


    }


    public class AlarmTag
    {
        // 是否报警
        private bool isAlarm = false;

        // 是否静音
        private bool isMuted = false;


        public bool IsAlarm
        {
            get => isAlarm;
            set
            {
                isAlarm = value;
                if (!value)
                {
                    isMuted = false;
                }
            }
        }

        public bool IsMuted { get => isMuted; }

        public bool IsSoundAlarm { get => isAlarm && !isMuted; }

        public void setMuted()
        {
            // 只有在报警状态才能设置静音
            if (IsAlarm)
            {
                isMuted = true;
            }
        }

    }
}
